/*
 * This file is part of yapk (yet another (auto) process killer) driver.
 *
 * Copyright (C) 2011 by Mateusz Wojcik <mewojcik@gmail.com>
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
#ifndef __YAPK_DRV_H__
#define __YAPK_DRV_H__

/*
 * Macros section.
 */
#if DBG
	#if defined(DRV_DBG)
		#error Redefinition of existing macro: DRV_DBG!
	#endif
	#define DRV_DBG(_msg_)	DbgPrint("yapk_drv: ");	\
								DbgPrint _msg_;

	#if defined(DRV_ERROR)
		#error Redefinition of existing macro: DRV_ERROR!
	#endif
	#define DRV_ERROR(_funcname_, _status_) DRV_DBG(	("%s() failed at line: %u cause of failure: %s, error code: %X\n", \
															__FUNCTION__, __LINE__, (_funcname_), (_status_)));
#else
	#if defined(DRV_DBG)
		#error Redefinition of existing macro: DRV_DBG!
	#endif
	#define DRV_DBG(_msg_)

	#if defined(DRV_ERROR)
		#error Redefinition of existing macro: DRV_ERROR!
	#endif
	#define DRV_ERROR(_funcname_, _dstatus_)
#endif

#if defined(DRV_COMPLETE_REQUEST)
	#error Redefinition of existing macro YAACMC_COMPLETE_REQUEST!
#endif
#define DRV_COMPLETE_REQUEST(_IRP_,_STATUS_,_INFO_,_INC_) 	(_IRP_)->IoStatus.Status = (_STATUS_);		\
															(_IRP_)->IoStatus.Information = (_INFO_);	\
															IoCompleteRequest((_IRP_), (_INC_));


/*
 * All constans and defines goes here.
 */

#define NT_DEVICE_NAME			L"\\Device\\Yapk_drv"
#define DOS_DEVICE_NAME			L"\\DosDevices\\Yapk_drv"
#define ALLOCATION_TAG			'kpay'

/*
 * Forward declarations goes here.
 */
DRIVER_INITIALIZE											DriverEntry;
DRIVER_UNLOAD												DriverUnload;
__drv_dispatchType(IRP_MJ_CREATE)
__drv_dispatchType(IRP_MJ_CLOSE) 			DRIVER_DISPATCH DriverCreateClose;
__drv_dispatchType(IRP_MJ_DEVICE_CONTROL) 	DRIVER_DISPATCH DriverDeviceControl;
VOID PsNotifyCreateProcessRoutine (IN HANDLE  ParentId, IN HANDLE  ProcessId, IN BOOLEAN  Create);


/*
 * Driver internal structures.
 */

/**
 * @struct YapkDevExtension
 * This structure is holding internal device object elements 
 * used across this driver.
 */
typedef struct _YapkDevExtension
{
	LIST_ENTRY	ProcessNameListHead;					/**< Process name list head.	*/
	FAST_MUTEX	ProcessNameListGuard;					/**< Process name list mutex.	*/
} YapkDevExtension, *PYapkDevExtension;
#define SIZEOF_YAPK_DEV_EXTENSION	sizeof(YapkDevExtension)

#define STRING_MAX 255

/**
 * @struct YapkProcessEntry
 * This Struct reresents single entry inside ProcessName list.
 */
typedef struct _YapkProcessEntry
{
	CHAR			ProcessName[STRING_MAX];			/**< Process name string.		*/
	LIST_ENTRY		Entry;								/**< Process information entry.	*/
} YapkProcessEntry, *PYapkProcessEntry;
#define SIZEOF_YAPK_PROCESS_ENTRY sizeof(YapkProcessEntry)

#endif /*__YAPK_DRV_H__*/

